﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using SyncCommon; 

namespace SyncWebSite
{
    public class Sync51tie : SyncHouseBase
    {
        private Dictionary<string, string> loginCookies = new Dictionary<string, string>();
        private List<string> retImages = new List<string>();
        private List<string> retthumbImages = new List<string>();
        private string targetID;
        private string CityID;
        private string CityShortName;
        private Encoding outEncoding = Encoding.GetEncoding("GB2312");
        private string ZoneID;
        private string StreetID;
        public Sync51tie(string user, string password)
            : base(user, password)
        {

        }

        #region SyncHouseBase
        public override bool CheckLogin()
        {
            WebRequest request = new WebRequest("http://www.51tie.com/do/login.php?f", FormType.FormUrlEncode, outEncoding, outEncoding);
            request.Cookies = loginCookies;
            request.AddStringCookies("USR=ddvv6otk%093%091347780423%09http%3A%2F%2Fwww.51tie.com%2Fdo%2Flogin.php; From_City=116; AJSTAT_ok_pages=5; AJSTAT_ok_times=1; Hm_lvt_6dcb66034aed7493a93ef9b231ecaf14=1347780130955; Hm_lpvt_6dcb66034aed7493a93ef9b231ecaf14=1347780420300; choose_cityID=116");
            request.AddContent("username", UserName);
            request.AddContent("password", Password);
            request.AddContent("step", "2");
            request.AddContent("fromurl", "http://sh.51tie.com/");
            request.AddContent("imageField.x", "70");
            request.AddContent("imageField.y", "13");

       
            string status = request.SendWaitString();

            if (status.Contains("登录成功") || status.Contains("你已经登录了,请不要重复登"))
            {
                return true;
            }
            return false;
        }

        public override bool AddSaleHouse(HouseInfo info, ref string targetID)
        {
            UpdateCurrentStatus(StandardProgress.InitalData);

            try
            {
                if (!CheckLogin())
                {
                    UpdateCurrentStatus(StandardProgress.Failed, "登录失败");
                    return false;
                }
                else
                {
                    string errorInfor = "";
                    if (!CommonCheck(info, true, ref errorInfor))
                    {
                        UpdateCurrentStatus(StandardProgress.Failed, errorInfor);
                        return false;
                    }
                    GetCityInfo(info.City);
                    GetEsateInfo(info);
                    WebRequest request = new WebRequest("http://www.51tie.com/do/hack.php?hack=login&iframeID=head_loginer&styletype=0");
                    request.Cookies = loginCookies;
                    request.GetResouceStr();

                    UpdateCurrentStatus(StandardProgress.PosData);
                    request = new WebRequest("http://" + CityShortName + ".51tie.com/post.php?action=postclass", FormType.MultiPart, Encoding.GetEncoding("GB2312"));
                    request.ReturnEncoding = outEncoding;
                    request.SetHeaderValue("Host", CityShortName + ".51tie.com");
                    //需要修改。
                    request.SetHeaderValue("Referer", "http://sh.51tie.com/post-13-116-1651.html");
                    request.Cookies = loginCookies;
                    request.AddStringCookies("AJSTAT_ok_times=3; AJSTAT_ok_pages=6; choose_cityID=116; From_City=116;");
                    //request.AddStringCookies("AJSTAT_ok_times=3; AJSTAT_ok_pages=6; USR=lcjpkzhs%0931%091346165557%09http%3A%2F%2Fwww.51tie.com%2Fdo%2Fhack.php%3Fhack%3Dlogin%26job%3Djs; Hm_lvt_6dcb66034aed7493a93ef9b231ecaf14=1346138318140,1346141850921,1346160926140,1346162339515; choose_cityID=116; pgv_pvi=9415670784; From_City=116; Hm_lpvt_6dcb66034aed7493a93ef9b231ecaf14=1346165548343; passport=835279%09testpwd2%09VloAVwAHDVFUDlFXVQZXVl8MBwNUA1AKUQJTVVcGVFc%3Dd96c2b4756; pgv_si=s4063654912");


                    request.AddContent("fid", GetRentSaleID(info));
                    request.AddContent("fidname", "二手房买卖");
                    FillPostData(info, request);


                    string status = request.SendWaitString();

                    //<a href="http://sh.51tie.com/fang2/f8960185.shtml">如果您的浏览器没有自动跳转,请点击这里</a>

                    if (status.Contains("发表成功"))
                    {
                        Regex reg = new Regex("<a href=\"(?<dizhi>.*?)\">如果您的浏览器没有自动跳转,请点击这里</a>");
                        Match ma = reg.Match(status);

                        if (ma.Success)
                        {
                            string url = ma.Groups["dizhi"].Value;
                            reg = new Regex(@"(?<=/f)\d*?(?=.shtml)");
                            targetID = reg.Match(url).Value;
                            //targetID = "fid=" + GetRentSaleID(info) + "&id=" + targetID;
                            UpdateCurrentStatus(StandardProgress.Sucess, "", targetID, url);
                            return true;
                        }
                        else
                        {
                            UpdateCurrentStatus(StandardProgress.Failed, "发布失败");
                            return false;
                        }
                    }
                    else
                    {
                        //信息提示:</span> 请勿提交雷同信息 </br>
                        Regex reg = new Regex("信息提示:</span>(?<errorinof>.*?)</br>");
                        string error = "";
                        Match ma = reg.Match(status);
                        if (ma.Success)
                        {
                            error = ma.Groups["errorinof"].Value;
                        }
                        UpdateCurrentStatus(StandardProgress.Failed, string.IsNullOrEmpty(error) ? "发布失败" : error);
                        return false;
                    }
                }
            }
            catch (System.Net.WebException exp)
            {
                UpdateCurrentStatus(StandardProgress.Failed, WebError);
                return false;
            }
            catch (Exception exp)
            {
                UpdateCurrentStatus(StandardProgress.Failed, exp.Message);
                return false;
            }
        }

        private void FillPostData(HouseInfo info, WebRequest request)
        {
            request.AddContent("postdb[title]", info.Title);
            request.AddContent("postdb[keywords]", info.SearchKey);

            request.AddContent("postdb[city_id]", CityID);

            request.AddContent("postdb[zone_id]", ZoneID);

            request.AddContent("postdb[street_id]", StreetID);

            request.AddContent("postdb[gongxu]", "1");


            request.AddContent("postdb[my_542]", info.LocalAddress);

            request.AddContent("postdb[laiyuan]", "2");


            request.AddContent("postdb[my_278]", GetRoom(info.Room));


            request.AddContent("postdb[my_119]", info.CurrentFloor);
            request.AddContent("postdb[my_276]", GetToward(info.Toward));


            request.AddContent("postdb[my_198]", info.Age);

            request.AddContent("postdb[my_393]", GetDecoration(info.Decoration));


            request.AddContent("postdb[my_288]", info.Area);

            request.AddContent("postdb[jiawei]", GetPriceArea(info.Price));

            request.AddContent("postdb[my_433]", GetPrice(info));

            request.AddContent("postdb[content]", info.Description);

            request.AddContent("postdb[sortid]", "1");

            request.AddContent("postdb[picurl]", info.Images != null && info.Images.Length > 0 ? info.Images[0] : "");


            request.AddContent("ftype[1]", "out");

            request.AddContent("postdb[linkman]", info.Name);

            request.AddContent("postdb[telephone]", info.Mobile);

            request.AddContent("postdb[mobphone]", "");

            request.AddContent("postdb[oicq]", "");

            request.AddContent("postdb[email]", "");
            request.AddContent("postdb[showday]", "90");

            request.AddContent("local_file1", "");
            request.AddContent("id", "0");
            request.AddContent("fid_bak1", "");
            request.AddContent("fid_bak2", "");
            request.AddContent("fid_bak3", "");

        }
        public override bool AddRentHouse(HouseInfo info, ref string targetID)
        {
            UpdateCurrentStatus(StandardProgress.InitalData);
            try
            {
                if (!CheckLogin())
                {
                    UpdateCurrentStatus(StandardProgress.Failed, "登录失败");
                    return false;
                }
                else
                {
                    string errorInfor = "";
                    if (!CommonCheck(info, false, ref errorInfor))
                    {
                        UpdateCurrentStatus(StandardProgress.Failed, errorInfor);
                        return false;
                    }
                    GetCityInfo(info.City);
                    GetEsateInfo(info);
                    WebRequest request = new WebRequest("http://www.51tie.com/do/hack.php?hack=login&iframeID=head_loginer&styletype=0");
                    request.Cookies = loginCookies;
                    request.GetResouceStr();

                    UpdateCurrentStatus(StandardProgress.PosData);
                    request = new WebRequest("http://" + CityShortName + ".51tie.com/post.php?action=postclass", FormType.MultiPart, Encoding.GetEncoding("GB2312"));
                    request.ReturnEncoding = outEncoding;
                    request.SetHeaderValue("Host", CityShortName + ".51tie.com");
                    //需要修改。
                    request.SetHeaderValue("Referer", "http://sh.51tie.com/post-13-116-1651.html");
                    request.Cookies = loginCookies;
                    request.AddStringCookies("AJSTAT_ok_times=3; AJSTAT_ok_pages=6; choose_cityID=116; From_City=116;");
                    //request.AddStringCookies("AJSTAT_ok_times=3; AJSTAT_ok_pages=6; USR=lcjpkzhs%0931%091346165557%09http%3A%2F%2Fwww.51tie.com%2Fdo%2Fhack.php%3Fhack%3Dlogin%26job%3Djs; Hm_lvt_6dcb66034aed7493a93ef9b231ecaf14=1346138318140,1346141850921,1346160926140,1346162339515; choose_cityID=116; pgv_pvi=9415670784; From_City=116; Hm_lpvt_6dcb66034aed7493a93ef9b231ecaf14=1346165548343; passport=835279%09testpwd2%09VloAVwAHDVFUDlFXVQZXVl8MBwNUA1AKUQJTVVcGVFc%3Dd96c2b4756; pgv_si=s4063654912");

                    request.AddContent("fid", GetRentSaleID(info));

                    request.AddContent("postdb[my_956]", info.MonthPrice);
                    request.AddContent("postdb[my_987]", GetPayment(info));
                    request.AddContent("postdb[my_255]", GetRentPriceArea(info.MonthPrice));
                    request.AddContent("postdb[my_430]", info.CurrentFloor);
                    request.AddContent("postdb[my_642]", info.Area);

                    request.AddContent("postdb[my_769]", GetRoom(info.Room));
                    request.AddContent("postdb[my_223]", GetDecoration(info.Decoration));
                    request.AddContent("fidname", "出租房");
                    FillPostData(info, request);


                    string status = request.SendWaitString();

                    //<a href="http://sh.51tie.com/fang2/f8960185.shtml">如果您的浏览器没有自动跳转,请点击这里</a>

                    if (status.Contains("发表成功"))
                    {
                        Regex reg = new Regex("<a href=\"(?<dizhi>.*?)\">如果您的浏览器没有自动跳转,请点击这里</a>");
                        Match ma = reg.Match(status);

                        if (ma.Success)
                        {
                            string url = ma.Groups["dizhi"].Value;
                            reg = new Regex(@"(?<=/f)\d*?(?=.shtml)");
                            targetID = reg.Match(url).Value;
                            //http://www.51tie.com/f/post.php?action=del&fid=12&id=9122005
                            //targetID = "fid=" + GetRentSaleID(info) + "&id=" + targetID;
                            UpdateCurrentStatus(StandardProgress.Sucess, "", targetID, url);
                            return true;
                        }
                        else
                        {
                            UpdateCurrentStatus(StandardProgress.Failed, "发布失败");
                            return false;
                        }
                    }
                    else
                    {
                        //信息提示:</span> 请勿提交雷同信息 </br>
                        Regex reg = new Regex("信息提示:</span>(?<errorinof>.*?)</br>");
                        string error = "";
                        Match ma = reg.Match(status);
                        if (ma.Success)
                        {
                            error = ma.Groups["errorinof"].Value;
                        }
                        UpdateCurrentStatus(StandardProgress.Failed, string.IsNullOrEmpty(error) ? "发布失败" : error);
                        return false;
                    }
                }
            }
            catch (System.Net.WebException exp)
            {
                UpdateCurrentStatus(StandardProgress.Failed, WebError);
                return false;
            }
            catch (Exception exp)
            {
                UpdateCurrentStatus(StandardProgress.Failed, exp.Message);
                return false;
            }
        }

        public override bool DeleteRentHouse(HouseInfo info, string targetID)
        {
            return InnerDelete(targetID,"12");
        }

        private bool InnerDelete(string targetID,string fid)
        {
            UpdateCurrentStatus(StandardProgress.InitalData);
            try
            {

                if (CheckLogin())
                {
                    WebRequest request = new WebRequest("http://www.51tie.com/f/post.php?action=del&fid=" + fid + "&id=" + targetID);
                    request.Cookies = loginCookies;
                    request.ReturnEncoding = outEncoding;
                    UpdateCurrentStatus(StandardProgress.PosData);
                    string status = request.GetResouceStr();
                    if (status.Contains("删除成功"))
                    {
                        UpdateCurrentStatus(StandardProgress.Sucess, "");
                        return true;
                    }
                    else
                    {
                        Regex reg = new Regex("信息提示:</span>(?<errorinof>.*?)</br>");
                        string error = "";
                        Match ma = reg.Match(status);
                        if (ma.Success)
                        {
                            error = ma.Groups["errorinof"].Value;
                        }
                        UpdateCurrentStatus(StandardProgress.Failed, string.IsNullOrEmpty(error) ? "删除信息失败" : error);
                        LogCenter.LogMessage("删除信息失败。提交值ID:" + targetID ?? "" + "返回值:" + status ?? "");
                        return false;
                    }
                }
                else
                {
                    UpdateCurrentStatus(StandardProgress.Failed, "登陆失败");
                    return false;
                }
            }
            catch (System.Net.WebException exp)
            {
                UpdateCurrentStatus(StandardProgress.Failed, WebError);
                return false;
            }
        }
        public override bool DeleteSaleHouse(HouseInfo info, string targetID)
        {
            return  InnerDelete(targetID,"13");
        }
        public override bool RefreshRentHouse(HouseInfo info, string targetID)
        {
            //../job.php?job=update&fid=12&id=9157551
          return  InnserRefresh(targetID, "12");
        }
        public override bool RefreshSaleHouse(HouseInfo info, string targetID)
        {
          
            //../job.php?job=update&fid=13&id=9157551
          return  InnserRefresh(targetID, "13");
        }

        private bool InnserRefresh(string targetID, string fid)
        {
            UpdateCurrentStatus(StandardProgress.InitalData);
            try
            {
                if (CheckLogin())
                {
                    WebRequest request = new WebRequest("http://www.51tie.com/f/job.php?job=update&fid=" + fid + "&id=" + targetID);
                    request.Cookies = loginCookies;
                    request.ReturnEncoding = outEncoding;
                    UpdateCurrentStatus(StandardProgress.PosData);
                    string status = request.GetResouceStr();
                    if (status.Contains("刷新成功"))
                    {
                        UpdateCurrentStatus(StandardProgress.Sucess, "");
                        return true;
                    }
                    else
                    {
                        string error = "";
                        if (status.Contains("积分不足"))
                        {
                            error = "积分不足,不能刷新";
                        }
                        else
                        {
                            Regex reg = new Regex("信息提示:</span>(?<errorinof>.*?)</br>");
                            Match ma = reg.Match(status);
                            if (ma.Success)
                            {
                                error = ma.Groups["errorinof"].Value;
                            }
                        }
                        UpdateCurrentStatus(StandardProgress.Failed, string.IsNullOrEmpty(error) ? "刷新信息失败" : error);
                        LogCenter.LogMessage("刷新信息失败。提交值ID:" + targetID ?? "");
                        return false;
                    }
                }
                else
                {
                    UpdateCurrentStatus(StandardProgress.Failed, "登陆失败");
                    return false;
                }
            }
            catch (System.Net.WebException exp)
            {
                UpdateCurrentStatus(StandardProgress.Failed, WebError);
                return false;
            }
        }
     

        public void SyncImages(HouseInfo info, ref string status)
        {
            status = "";
        }

        

        public void Refresh(string HefaCode, ref string status)
        {
            WebRequest request = new WebRequest(string.Format("http://www.51tie.com/f/job.php?job=update&fid=13&id={0}", HefaCode));
            request.Cookies = loginCookies;
            request.GetResouceStr();
        }
        #endregion

        #region HelpFunction

        public string GetPrice(HouseInfo info)
        { 
            double moneny = 0;
            if (double.TryParse(info.Price, out moneny))
            {
                return Math.Round(moneny).ToString();
            }
            else
            {
                throw new Exception("价格不是有效数字");
            }
            
        }

        public void GetEsateInfo(HouseInfo info)
        {

            WebRequest newrequest = new WebRequest("http://" + CityShortName + ".51tie.com/post-12-" + CityID + ".html");
            newrequest.Cookies = loginCookies;
            newrequest.ReturnEncoding = outEncoding;
            string ret = newrequest.GetResouceStr();
            string district = HtmlHelper.RemoveAddtionalDistrict(info.LocalDistrict);
            Regex reg = new Regex("<a href='http://" + CityShortName + ".51tie.com/post-12-" + CityID + "-(?<district>\\d*?).html'>" + district + ".*?</a>");
            Match ma = reg.Match(ret);
            if (ma.Success)
            {
                ZoneID = ma.Groups["district"].Value;

            }
            else
            {
                throw new UnFindDistrictException(district);
            }

            newrequest = new WebRequest("http://" + CityShortName + ".51tie.com/post-12-" + CityID + "-" + ZoneID + ".html");
            newrequest.ReturnEncoding = outEncoding;
            newrequest.Cookies = loginCookies;
            ret = newrequest.GetResouceStr();
            string street = HtmlHelper.RemoveAddtionalStreet(info.LocalDiduan);
            //<a href="post-13-34-310-721.html">太升路</a>
            reg = new Regex("<a href=\"post-12-" + CityID + "-" + ZoneID + "-" + "(?<street>\\d*?).html\">" + street + ".*?</a>");

            ma = reg.Match(ret);
            if (ma.Success)
            {
                StreetID = ma.Groups["street"].Value;
            }
            else
            {
                throw new UnFindDiduanException(street);
            }
            LogCenter.LogMessage("51同城匹配区县,区:" + info.LocalDistrict + "县:" + info.LocalDiduan + "匹配后:" + ZoneID + "," + StreetID);

        }


        public void GetCityInfo(string cityname)
        {
            WebRequest request = new WebRequest("http://www.51tie.com/allcity.php");
            request.ReturnEncoding = outEncoding;
            string ret = request.GetResouceStr();

            //<a href="http://lyg.51tie.com/" style="">连云港</a>
            Regex reg = new Regex("<a href=\"http://(?<short>\\w*?)\\.51tie\\.com/\" style=\".*?\">" + cityname + "</a>");

            MatchCollection matchs = reg.Matches(ret);
            if (matchs.Count > 0)
            {
                CityShortName = matchs[0].Groups["short"].Value;
            }

            request = new WebRequest("http://" + CityShortName + ".51tie.com/");
            request.ReturnEncoding = outEncoding;
            request.Cookies = loginCookies;
            request.GetResouceStr();
            CityID = request.Cookies["city_id"];
        }

        public string GetPayment(HouseInfo info)
        {
            //当前 1:付一押一 2:付二押一 3:付三押一 4:付六押一
            //目标汉字
            switch (info.PayType)
            { 
                case "0":
                    return "面议";
                case "1":
                    return "付一押一";
                case "2":
                    return "付二押一";
                case "3":
                    return "付三押一";
                case "4":
                    return "付六押一";

            }
            return "面议";
        }
        public string GetRentSaleID(HouseInfo info)
        {
            if (info.TradeType == TradeType.Rent)
            {
                return "12";
            }
            //13是出售
            return "13";
        }

        public string GetRoom(string room)
        {
            int temp = 1;
            int.TryParse(room, out temp);
            if (temp > 5)
            {
                return "6";
            }
            return room;
            
        }

        public string GetToward(string toward)
        {
            //当前 1=东 2=南 3=西 4=北 5=南北 6=东西 7=东南 8=西南 9=东北 10=西北 11=不知道朝向
            //目标 东 南 西 北 东南 东北 西南 西北 南北   
            if (toward == "1")
            {
                return "东";
            }
            if (toward == "2")
            {
                return "南";
            }
            if (toward == "3")
            {
                return "西";
            }
            if (toward == "4")
            {
                return "北";
            }
            if (toward == "5")
            {
                return "南北";
            }
        
            if (toward == "7")
            {
                return "东南";
            }
            if (toward == "8")
            {
                return "西南";
            }
            if (toward == "9")
            {
                return "东北";
            }
            if (toward == "10")
            {
                return "西北";
            }
            return "东";
        }


        public string GetDecoration(string dec)
        { 
            //当前 1:毛胚 2:简装 3:精装 4:豪装
            //目标 无装修 简单装修 中等装修 精装修 豪华装修
            if (dec == "1")
            {
                return "无装修";
            }
            if (dec == "2")
            {
                return "简单装修";
            }
            if (dec == "3")
            {
                return "精装修";
            }
            if (dec == "4")
            {
                return "豪华装修";
            }
            return "简单装修";
        }

        public string GetPriceArea(string price)
        {
            int priceInt = 0;
            int.TryParse(price, out priceInt);
            if (priceInt <= 50)
            {
                return "1";
            }
            if (priceInt <= 80)
            {
                return "2";
            }

            if (priceInt <= 120)
            {
                return "3";
            }
            if (priceInt <= 180)
            {
                return "4";
            }
            if (priceInt <= 250)
            {
                return "5";
            }
            if (priceInt <= 400)
            {
                return "6";
            }
            if (priceInt <= 800)
            {
                return "7";
            }
            if (priceInt > 800)
            {
                return "8";
            }
            return "1";
        }


        public string GetRentPriceArea(string price)
        {
            int priceInt = 0;
            if(price =="面议")
            {
                return "1";
            }
            int.TryParse(price, out priceInt);
     
            if (priceInt <= 500)
            {
                return "2";
            }

            if (priceInt <= 1000)
            {
                return "3";
            }
            if (priceInt <= 1500)
            {
                return "4";
            }
            if (priceInt <= 2000)
            {
                return "5";
            }
            if (priceInt <= 3000)
            {
                return "6";
            }
            if (priceInt <= 5000)
            {
                return "7";
            }
            if (priceInt <= 8000)
            {
                return "8";
            }
            if (priceInt <= 10000)
            {
                return "9";
            }
            if (priceInt > 10000)
            {
                return "10";
            }
            return "1";
        }
        #endregion

        #region 编辑功能
        public override bool OpenEidt(WebBrowserOp op, HouseInfo info)
        {
            try
            {
                if (CheckLogin())
                {
                    if (string.IsNullOrEmpty(CityID))
                    {
                        CityID = "116";
                        CityShortName = "sh";
                    }
                    try
                    {
                        GetEsateInfo(info);
                    }
                    catch
                    { }

                    if (string.IsNullOrEmpty(ZoneID) || string.IsNullOrEmpty(StreetID))
                    {
                        string post = "http://sh.51tie.com/post-116.html";
                        foreach (KeyValuePair<string, string> k in loginCookies)
                        {
                            WebBrowserOp.InternetSetCookie(post, k.Key, k.Value);
                        }
                        op.HouseInformation = info;
                        op.Navigate(post);
                    }
                    else
                    {
                        
                        if (info.TradeType == TradeType.Sale)
                        {
                            string post = "http://sh.51tie.com/post-13-116-" + ZoneID + "-" + StreetID + ".html";
                            foreach (KeyValuePair<string, string> k in loginCookies)
                            {
                                WebBrowserOp.InternetSetCookie("http://www.51tie.com/do/hack.php?hack=login&job=js", k.Key, k.Value);
                                WebBrowserOp.InternetSetCookie(post, k.Key, k.Value);
                            }
                            op.HouseInformation = info;
                            op.Navigate(post);
                            op.Completed += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(op_Sale_Completed);
                        }
                        else
                        {
                            string post = "http://sh.51tie.com/post-12-116-" + ZoneID + "-" + StreetID + ".html";
                            foreach (KeyValuePair<string, string> k in loginCookies)
                            {
                                WebBrowserOp.InternetSetCookie("http://www.51tie.com/do/hack.php?hack=login&job=js", k.Key, k.Value);
                                WebBrowserOp.InternetSetCookie(post, k.Key, k.Value);
                            }
                            op.HouseInformation = info;
                            op.Navigate(post);
                            op.Completed += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(op_Rent_Completed);
                        }
                    }
                }
                else
                {
                    return false;
                }
            }
            catch
            {
                op.Navigate("http://www.51tie.com/");
            }
            return true;
        }
        void op_Sale_Completed(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
        {
            WebBrowserOp cl = sender as WebBrowserOp;
            HouseInfo info = cl.HouseInformation;
            cl.SetValueByID("topic", info.Title);

            cl.SetValueByName("postdb[keywords]", info.SearchKey);

            cl.CheckByName_Value("postdb[gongxu]","1" ,true);

            cl.SetValueByID("atc_my_542", info.Estate);
            cl.CheckByName("postdb[laiyuan]", true);
            cl.SelectByID_Value("atc_my_278", GetRoom(info.Room));
            cl.SetValueByID("atc_my_119", info.CurrentFloor);
            cl.CheckByName_Value("postdb[my_276]", GetToward(info.Toward), true);

            cl.SetValueByID("atc_my_198", info.Age);

            cl.SelectByID_Value("atc_my_393", GetDecoration(info.Decoration));

            cl.SetValueByID("atc_my_288", info.Area);
            cl.SelectByID_Value("atc_jiawei", GetPriceArea(info.Price));
            cl.SetValueByID("atc_my_433", info.Price);
            cl.SetValueByID("contents", info.Description);
            if (info.Images.Length > 0)
            {
                cl.SetValueByID("out_url1", info.Images[0]);
            }
            cl.SetValueByID("atc_linkman", info.Name);
            cl.SetValueByID("tel", info.Mobile);

        }
        void op_Rent_Completed(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
        {
            WebBrowserOp cl = sender as WebBrowserOp;
            HouseInfo info = cl.HouseInformation;
            cl.SetValueByID("topic", info.Title);

            cl.SetValueByName("postdb[keywords]", info.SearchKey);

            cl.CheckByName("postdb[laiyuan]", true);
             
            cl.SetValueByID("atc_my_956", info.MonthPrice);

            cl.SetValueByID("atc_my_987", GetPayment(info));

            cl.SetValueByID("atc_my_430", info.CurrentFloor);
            cl.SetValueByID("atc_my_642", info.Area);
            cl.SelectByID_Value("atc_my_255", GetRentPriceArea(info.MonthPrice));
            cl.SelectByID_Value("atc_my_769", GetRoom(info.Room));
            cl.SelectByID_Value("atc_my_223", GetDecoration(info.Decoration));


            cl.SetValueByID("contents", info.Description);

            if (info.Images.Length > 0)
            {
                cl.SetValueByID("out_url1", info.Images[0]);
            }
            cl.SetValueByID("atc_linkman",info.Name);
            cl.SetValueByID("tel", info.Mobile);


        }
        #endregion
    }
}
